from weibosender.dal.senders_dal import SendersDAL
from weibosender.dal.receivers_dal import ReceiversDAL
from weibosender.weibo.weibo_login_handler import WeiboLoginHandler
from weibosender.weibo.weibo_send_msg_handler import WeiboSendMsgHandler
from weibosender.weibo.weibo_gather_handler import WeiboGatherHandler


class WeiboHelper:
    _msg_content = '您好，我是超级圈APP的运营LULU。\
                    \n超级圈以电话咨询和文字沟通的方式让拥有专业知识的人可以利用闲余时间提供简单的咨询服务，并且按照通话分钟和文字问答收费，价格由您自定。\
                    \n看了您的微博和相关介绍，我非常想邀请您加入我们平台，来为超级圈的用户提供专业的咨询服务，我们也期待您在体验之后能从专业角度给我们建议或吐槽。\
                    \n如果您愿意尝试在超级圈帮助有需要的人，请您回复或者加我的微信：superqlu。'

    @staticmethod
    def login():
        users = SendersDAL.get_login_senders()
        if not users or len(users) < 1:
            return None
        return WeiboLoginHandler.login(users)

    @staticmethod
    def send_msg():
        senders = SendersDAL.get_senders()
        if not senders or len(senders) < 1:
            print('没有可用于发送私信的账号')
            return None
        receivers = ReceiversDAL.get_receivers()
        if not receivers or len(receivers) < 1:
            print('没有可发送私信的用户，请选择采集用户')
            return None
        handler = WeiboSendMsgHandler(senders, receivers, WeiboHelper._msg_content)
        handler.send()
        return True

    @staticmethod
    def gather_user():
        handler = WeiboGatherHandler()
        handler.start()

        while 1:
            cmd = input()
            if cmd == 'c':
                handler.stop()
                handler.join()
                print('采集已中断')
                break
